package com.hsshy.beam.sharding.service;


import com.hsshy.beam.sharding.entity.Order;
import com.hsshy.beam.sharding.entity.OrderItem;
import com.hsshy.beam.sharding.dao.OrderItemMapper;
import com.hsshy.beam.sharding.dao.OrderMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class DemoService {
    
    @Resource
    private OrderMapper orderMapper;
    
    @Resource
    private OrderItemMapper orderItemMapper;
    
    public void demo() {

        for (int i = 0; i < 100; i++) {
            Order order = new Order();
            order.setUserId(i);
            order.setStatus("INSERT_TEST");
            orderMapper.insert(order);
            long orderId = order.getOrderId();

            OrderItem item = new OrderItem();
            item.setOrderId(orderId);
            item.setUserId(i);
            item.setStatus("INSERT_TEST");
            orderItemMapper.insert(item);
        }

    }

    public void demo1(Long userId,Long orderId) {

//        System.out.println(orderItemMapper.selectAll());
        List<Map> mapList = orderItemMapper.selectList(userId,orderId);
        if(mapList.size()>0){
//            System.out.println(mapList);
            for(int i=0;i<mapList.size();i++){
                if(mapList.get(i)==null){
                    continue;
                }
                System.out.println("第"+i+"个userId:"+mapList.get(i).get("user_id")+"--"+mapList.get(i).get("order_id"));

            }
        }


    }
}
